package com.cloud.controller.user;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cloud.bean.user.User;
import com.cloud.common.BaseReturn;
import com.cloud.controller.login.from.FromUser;
import com.cloud.service.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static com.cloud.common.JwtUtils.getByToken;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liuyuan
 * @since 2022-07-21
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @RequestMapping("/queryList")
    public BaseReturn queryList(@RequestBody FromUser fromUser){
        User user = getByToken();
        if(user == null){
            return  BaseReturn.build("4003","登录失效");
        }
        String customerNo = user.getCustomerNo();
        fromUser.setCustomerNo(customerNo);
        QueryWrapper<User> queryWrapper = new QueryWrapper<>(fromUser);
        Page<User> page = new Page<>(fromUser.getPage(),fromUser.getSize());
        IPage<User> list = userService.page(page, queryWrapper);
        List<User> records = list.getRecords();
        for (User user1:records) {
            user1.setPassword(null);
        }
        list.setRecords(records);
        return  BaseReturn.build("2000","查询成功",list);
    }

}

